import java.util.ArrayList;
import java.util.List;

public class Test {
    public static void main1(String[] args) throws InterruptedException {
        Thread t = new Thread() {
            @Override
            public void run() {
                while(true) {
                    System.out.println("hello world");
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        Runnable r = new Runnable(){

            @Override
            public void run() {
                while(true) {
                    System.out.println("hello runnable!");
                    try {
                        Thread.sleep(3000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        Thread t2 = new Thread(r);

        t.start();
        t2.start();
        while(true) {
            System.out.println("hello main");
            Thread.sleep(1000);
        }
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        Test test = new Test();
        test.permute(arr);
    }

    List<List<Integer>> list = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        int n = nums.length;
        dfs(new ArrayList<Integer>(), nums, n);
        return list;
    }
    void dfs(List<Integer> _path, int[] nums, int len) {
        List<Integer> path = new ArrayList<>(_path);
        if(path.size() == len) {
            list.add(path);
            return;
        }
        for(int i = 0; i < len; i++) {
            if(path.contains(nums[i])) {
                continue;
            }
            path.add(nums[i]);
            dfs(path, nums, len);
        }
    }

    List<List<Integer>> list2 = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        dfs2(new ArrayList<Integer>(), nums, 0);
        return list;
    }
    void dfs2(List<Integer> _path, int[] nums, int i) {
        List<Integer> path = new ArrayList<>(_path);
        //递归出口
        if(nums.length == i) {
            list.add(path);
            return;
        }
        //选择
        path.add(nums[i]);
        dfs(path, nums, i+1);

        //不选择
        path.remove(path.size() - 1);
        dfs(path, nums, i+1);
    }


}
